/**
 * 套保类资产,时间搜索
 */


import React, { PropTypes, PureComponent } from 'react';
import { Form, DatePicker, Button, Row, Col, message } from 'antd';

import moment from 'moment';
import 'moment/locale/zh-cn';
moment.locale('zh-cn');

const FormItem = Form.Item;
const RangePicker = DatePicker.RangePicker;

/**
 * 日期选择控件
 * @param {[type]} dispatch  [方法]
 * @param {[type]} beginDate [开始时间]
 * @param {[type]} endDate   [结束时间]
 * @param {[type]} tag       [所属model]
 */

const dateFormat = 'YYYY/MM/DD';
const nowDate = moment(new Date()).format('YYYYMMDD');
message.config({
  duration: 5,
});
const DateRangePicker=({tag,dispatch,location,begindate,enddate})=>{
	console.log("location>>>",location,begindate,enddate)

	const myProps={
		onChange:(date, dateString)=> {
      console.log("vvvvvv",date, dateString);
			if(_.isEmpty(date)&&_.isEmpty(dateString)){
				
				dispatch({
					type: `${tag}/setState`,
					payload: {
						begindate:'',
						enddate:''
					}
				})
			}else{
				const beginDate = moment(dateString[0]).format('YYYYMMDD');
	      const endDate = moment(dateString[1]).format('YYYYMMDD');
	      console.log("vvvvvv2", beginDate,endDate);
				if(beginDate && endDate){
					dispatch({
						type: `${tag}/setState`,
						payload: {
							begindate:beginDate,
							enddate:endDate
						}
					})
				}
			}
      
		},
	}
  return (
    <RangePicker
      {...myProps}
      defaultValue={[moment(begindate, dateFormat), moment(enddate, dateFormat)]}
      format={dateFormat}
      style={{ width: 200 }}
    />
  )
// 	if(location.hash.indexOf("begindate") > -1){
// 		const arr = location.hash.split('?')[1].split('&')
//     console.log("arr>>>>",arr);
// 		const BD = arr[0].split("=")[1];
// 		const ED = arr[2].split("=")[1];
//     console.log("0000000",BD,ED);
// 		return (
// 			<RangePicker
// 				{...myProps}
// 				defaultValue={[moment(BD, dateFormat), moment(ED, dateFormat)]}
// 				format={dateFormat}
// 				style={{ width: 200 }}
// 			/>
// 		)
// 	}else{
// 		return (
// 			<RangePicker
// 				{...myProps}
// 				defaultValue={[moment(nowDate, dateFormat), moment(nowDate, dateFormat)]}
// 				format={dateFormat}
// 				style={{ width: 200 }}
// 			/>
// 		)
// }

}
export default DateRangePicker;
